var e = require("../@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.toastToPage = exports.toastThen = exports.throttling = exports.throttle = exports.promising = exports.isToday = exports.isMoreThanNow = exports.isLessThanNow = exports.getWechatLoginCode = exports.getUrlOptions = exports.getRemainingDays = exports.getNowPage = exports.getDifferentDays = exports.formatTime = exports.formatIosTime = exports.debounce = exports.checkMobile = exports.callWeChatPay = exports.addDate = void 0;

var t = require("../@babel/runtime/helpers/createForOfIteratorHelper"), n = require("../@babel/runtime/helpers/slicedToArray");

require("../@babel/runtime/helpers/Objectentries");

var r = e(require("../@babel/runtime/regenerator")), o = require("../@babel/runtime/helpers/asyncToGenerator"), a = e(require("../miniprogram_npm/@vant/weapp/toast/toast")), i = function(e) {
    return function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        return new Promise(function(n, r) {
            var o = Object.assign(t, {
                success: function(e) {
                    n(e);
                },
                fail: function(e) {
                    r(e);
                }
            });
            e(o);
        });
    };
};

exports.promising = i;

exports.checkMobile = function(e) {
    return /^1[23456789]\d{9}$/.test(e);
};

exports.toastThen = function(e) {
    (0, a.default)(e), setTimeout(function() {
        wx.navigateBack({
            delta: 1
        });
    }, 1e3);
};

exports.toastToPage = function(e, t) {
    (0, a.default)({
        message: e || "操作成功",
        duration: 3e3,
        onClose: function() {
            t && wx.navigateTo({
                url: t
            });
        }
    });
};

exports.throttling = function(e, t) {
    t = t || 3e3;
    var n = 0, r = null;
    return function() {
        var o = this, a = arguments, i = +new Date();
        i - n < t ? (clearTimeout(r), r = setTimeout(function() {
            n = i, e.apply(o, a);
        }, t)) : (n = i, e.apply(o, a));
    };
};

exports.throttle = function(e, t) {
    var n = 0;
    return function() {
        var r = this, o = arguments, a = +new Date();
        a - n >= t && (n = a, e.apply(r, o));
    };
};

exports.debounce = function(e, t, n) {
    if ("function" != typeof e) throw new TypeError("func must be an function");
    var r;
    return "boolean" == typeof t && (n = t, t = 300), "number" != typeof t && (t = 300), 
    "boolean" != typeof n && (n = !1), function() {
        for (var o = arguments.length, a = new Array(o), i = 0; i < o; i++) a[i] = arguments[i];
        var s, u = !r && n, c = this;
        return r && (clearTimeout(r), r = null), r = setTimeout(function() {
            r && (clearTimeout(r), r = null), n || (s = e.call.apply(e, [ c ].concat(a)));
        }, t), u && (s = e.call.apply(e, [ c ].concat(a))), s;
    };
};

exports.callWeChatPay = function(e, t, n) {
    var r = {
        timeStamp: e.timeStamp,
        nonceStr: e.nonceStr,
        package: e.package,
        paySign: e.paySign,
        signType: e.signType,
        success: function(e) {
            console.log(e), t(e);
        },
        fail: function(e) {
            console.log(e), n(e);
        }
    };
    wx.requestPayment(r);
};

var s = function() {
    var e = o(r.default.mark(function e() {
        var t;
        return r.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.next = 2, i(wx.login)();

              case 2:
                return t = e.sent, e.abrupt("return", t.code);

              case 4:
              case "end":
                return e.stop();
            }
        }, e);
    }));
    return function() {
        return e.apply(this, arguments);
    };
}();

exports.getWechatLoginCode = s;

var u = function(e) {
    return (e = e || "").replace(/-/g, "/");
};

exports.formatIosTime = u;

exports.isMoreThanNow = function(e) {
    return (e = new Date(u(e)).getTime()) > new Date().getTime();
};

exports.isLessThanNow = function(e) {
    return (e = new Date(u(e)).getTime()) < new Date().getTime();
};

exports.formatTime = function(e) {
    return e ? e.substring(0, 10).replace(/\-/g, ".") : "";
};

var c = function(e) {
    var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 15, n = new Date(u(e));
    n.setDate(n.getDate() + t);
    var r = n.getFullYear(), o = n.getMonth() + 1, a = n.getDate(), i = n.getHours(), s = n.getMinutes(), c = n.getSeconds();
    return "".concat(r, "/").concat(o, "/").concat(a, " ").concat(i, ":").concat(s, ":").concat(c);
};

exports.addDate = c;

exports.getRemainingDays = function(e, t) {
    t = t || new Date(), e = c(e);
    var n = new Date(e).getTime() - new Date(u(t)).getTime(), r = Math.floor(n / 864e5), o = n % 864e5, a = Math.floor(o / 36e5), i = o % 36e5, s = Math.floor(i / 6e4), p = i % 6e4, l = p % 6e4;
    Math.round(p / 1e3), Math.round(l / 1e3);
    return "".concat(r, "天").concat(a, "时").concat(s, "分");
};

exports.isToday = function(e) {
    if (!e) return !1;
    var t = new Date(e.toString().replace(/-/g, "/")), n = new Date();
    return t.setHours(0, 0, 0, 0) == n.setHours(0, 0, 0, 0);
};

exports.getDifferentDays = function(e, t) {
    return t = t ? new Date(u(t)).getTime() : new Date().getTime(), ((e = new Date(u(e)).getTime()) - t) / 864e5;
};

exports.getNowPage = function() {
    var e = getCurrentPages();
    if (e.length > 0) {
        for (var t = e[e.length - 1], r = t.route, o = t.options, a = "?", i = 0, s = Object.entries(o); i < s.length; i++) {
            var u = n(s[i], 2), c = u[0], p = u[1];
            a += "".concat(c, "=").concat(p, "&");
        }
        return a = a.substring(0, a.length - 1), "/".concat(r).concat(a);
    }
    return "/pages/index/index";
};

exports.getUrlOptions = function(e) {
    console.log(e);
    var n, r = decodeURIComponent(e).split("?")[1].split("&"), o = {}, a = t(r);
    try {
        for (a.s(); !(n = a.n()).done; ) {
            var i = n.value.split("=");
            o[i[0]] = i[1];
        }
    } catch (e) {
        a.e(e);
    } finally {
        a.f();
    }
    return o;
};